﻿using AutoMapper;
using MediatR;
using MyMES.Domain.zyy;
using MyMES.Error;
using MyMES.Infrastructure.Interface;

namespace MyMES.Writer.API.Application.Commends.BomOperates
{
    public class AddBomOperateHandler:IRequestHandler<AddBomOperatecommand,APIResult<BomOperate>>
    {
      
        private readonly IBaseRepository<BomOperate> baseRepository;
        private readonly IMapper mapper;

        public AddBomOperateHandler(IBaseRepository<BomOperate> baseRepository,IMapper mapper )
        {
            
            this.baseRepository = baseRepository;
            this.mapper = mapper;
        }
public async Task<APIResult<BomOperate>> Handle(AddBomOperatecommand request, CancellationToken cancellationToken)
        {
            try
            {
                APIResult<BomOperate> result = new APIResult<BomOperate>();
                result.Code = APIEnum.添加成功;
                result.Msg = "添加成功";
                var aa = mapper.Map<BomOperate>(request);
                var sql = "insert into  BomOperate (BOId,BomId,UserId,OperateTime,Content) values (@BOId,@BomId,@UserId,@OperateTime,@Content)";
                await baseRepository.Insert(aa, sql);
                return result;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
